<%-- 
    Document   : ChatPage
    Created on : 05 Apr 11, 20:53:04
    Author     : Erdiansyah
--%>
<%@page import="memory.User"%>
<%@page import="memory.Room"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.lang.Integer"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="database.database"%>
<%@page import="structure.Tree"%>
<%@include file="../included/redirectout.jspf" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Chat Page</title>
        <script type="text/javascript" src="<% out.print(application.getContextPath().toString());%>/script/ajax.js"></script>
        <script type="text/javascript" src="<% out.print(application.getContextPath().toString());%>/script/command.js"></script>
        <script type="text/javascript" src="<% out.print(application.getContextPath().toString());%>/script/admin.js"></script>
        <script type="text/javascript" src="<% out.print(application.getContextPath().toString());%>/script/chatroom.js"></script>
        <link type="text/css" rel="stylesheet" href="<% out.print(application.getContextPath().toString());%>/style/default.css"/>
        <link type="text/css" rel="stylesheet" href="<% out.print(application.getContextPath().toString());%>/style/chat.css"/>
        <link type="image/x-icon" rel="shortcut icon" href="<% out.print(application.getContextPath().toString());%>/imgsrc/wedchaticon.png"/>
    </head>
    <body onload="retrievefriend();">
        <div id="suram"><input type="button" value="suram" onclick="close('suram');"/></div>
            <% memory.Container tes = (memory.Container) getServletContext().getAttribute("cont");%>
            <%
                        if (tes.getOnlineuserlist().size() > 0) {
                            for (int i = 0; i < tes.getOnlineuserlist().size(); ++i) {
                                out.print(tes.getOnlineuserlist().get(i).getUsername());
                            }
                        }
                        if (tes.getRoomlist().size() > 0) {
                            for (int i = 0; i < tes.getRoomlist().size(); ++i) {
                                out.print(tes.getRoomlist().get(i).showInfoRoom());
                            }
                        }
                        for (int i = 0; i < tes.getChatroomlist().size(); ++i) {
                            out.print("<->");
                            out.print(tes.getChatroomlist().get(i).id);

                            out.print(tes.getChatroomlist().get(i).getUsername().getUsername());
                            out.print("<->");
                            out.print(tes.getChatroomlist().get(i).getTousername().getUsername());
                            out.print("<br/>");
                        }
            %>
        <div class="bodytopchat">
            <br/>
            <br/>
            <div class="textlinks">
                <a class="textlink" id="loginuser"><%= session.getAttribute("loginuser") %></a>
                <a class="textlink">|</a>
                <a class="textlink" href="Logout">Logout</a>
            </div>
            <div class="labelchat">wedChat!</div>
            <img alt="" class="wedimg" src="imgsrc/wedminiicon.png"/>
        </div>
        <div class="bodymidchat">

            <div id="suram"><input type="button" value="suram" onclick="tes()"/></div>
            <div class="categorypanel">
                <%
                            database db = new database();
                            db.createConnection();
                            ResultSet rs;

                            String output = "";

                            List<Integer> categoryList = new ArrayList<Integer>();
                            List<Integer> showcategoryList = new ArrayList<Integer>();

                            db.select("SELECT * FROM categorydb ORDER BY categoryid ASC");
                            rs = db.getResultSet();
                            while (rs.next()) {
                                categoryList.add(rs.getInt("categoryid"));
                            }

                            db.select("SELECT * FROM categorydb WHERE parentid = 0");
                            rs = db.getResultSet();
                            while (rs.next()) {
                                showcategoryList.add(rs.getInt("categoryid"));
                            }

                            output += "<ul>";
                            for (int j : showcategoryList) {
                                output += "<li>";
                                output += "<a href ='javascript:void();' onclick = 'javascript:expandTree(" + j + ")'>" + db.getCategoryName(j) + "</a>";
                                output += "<ul id = 'categorytree" + j + "'></ul>";
                                output += "</li>";
                            }
                            output += "</ul>";

                            db.closeConnection();
                %>

                <div><%= output%></div>
            </div>
            <div class="chatboxpanel">
                <div class="tabs" id="tabs">
                    <div class="titlechatorroom"><a href="javascript:void()" onclick="showchat('home','formhome')">Home</a></div>
                </div>
                <div class="contentchatbox" id="contentschatbox">
                    <div class="chatroom" name="hide" id="home"></div>
                </div>
                <div class="chatboxcommand" id="chatboxcommands">
                    <form id="formhome" class ="formchatbox" name="commandform" method="post" action="javascript:parsecommand('home','inputchatboxtext');">
                        <input type="text" name="inputchatboxtext" id="inputchatboxtext"/>
                    </form>
                </div>
                <div id="feedbackchatbox"></div>
            </div>
            <div class="friendpanel">
                <div id="titlefriend">
                    <b>friends</b>
                    <select name="selectmodefriend" onchange="changemodefriend()">
                        <option>show all friend</option>
                        <option>hide offline friend</option>
                    </select>
                </div>
                <div id="friendlist"></div>
            </div>
        </div>
        <div class="bodybottomchat">
            <br/>
            <br/>
            <br/>
            <%@include file="../included/footer.jspf" %>
        </div>
    </body>
</html>
